//
//  USWriteOffUserController.m
//  us
//
//  Created by karry on 2025/4/9.
//

#import "USWriteOffUserController.h"

@interface USWriteOffUserController ()

@end

@implementation USWriteOffUserController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"注销账户";
    
    UILabel *titleLab = [UILabel new];
    titleLab.text = @"注意事项";
    titleLab.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
    titleLab.textColor = UIColor.secondaryLabelColor;
    [self.view addSubview:titleLab];
    
    UILabel *infoLab = [UILabel new];
    infoLab.text = @"1. 删除账户后，包括你的记录，购买（无法退款）等所有已注册的内容将被删除。\n\n2. 删除您的账户将删除所有的数据，账户一旦注销，您将无法使用当前账户登录或找回该账户相关信息。\n\n3. 根据法律规定，某些情况我们可能需要保留数据一段时间，以符合法规。";
    infoLab.font = [UIFont systemFontOfSize:15];
    infoLab.numberOfLines = 0;
    infoLab.textColor = UIColor.secondaryLabelColor;
    [self.view addSubview:infoLab];
    
    UIButton *actionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [actionBtn addTarget:self action:@selector(readAction:) forControlEvents:UIControlEventTouchUpInside];
    [actionBtn setBackgroundImage:[UIImage imageNamed:@"login_unagree"] forState:0];
    [actionBtn setImage:nil forState:0];
    [actionBtn setImage:[UIImage imageNamed:@"login_agree"] forState:UIControlStateSelected];
    [self.view addSubview:actionBtn];
    
    UILabel *readLab = [UILabel new];
    readLab.text = @"我已经阅读并同意以上注意事项，同意退出";
    readLab.font = [UIFont systemFontOfSize:16 weight:UIFontWeightBold];
    [self.view addSubview:readLab];
    
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(16);
        make.top.mas_equalTo(self.view.mas_safeAreaLayoutGuideTop).mas_offset(30);
        make.right.mas_offset(-16);
    }];
    
    [infoLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(titleLab);
        make.top.mas_equalTo(titleLab.mas_bottom).mas_offset(6);
    }];
    
    [actionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(titleLab);
        make.top.mas_equalTo(infoLab.mas_bottom).mas_offset(60);
    }];
    
    [readLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(actionBtn.mas_right).mas_offset(6);
        make.centerY.mas_equalTo(actionBtn);
        make.right.mas_offset(-16).priority(250);
    }];
    
    UIButton *sureBtn = [UIButton us_fillButtonWithTitle:@"注销账户"];
    [sureBtn addTarget:self action:@selector(sureAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:sureBtn];
    
    UIButton *cancelBtn = [UIButton us_borderButtonWithTitle:@"取消"];
    [cancelBtn addTarget:self action:@selector(cancelAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:cancelBtn];
    
    [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(20);
        make.height.mas_equalTo(UIButton.us_buttonDefaultHeight);
        make.bottom.mas_equalTo(self.view.mas_safeAreaLayoutGuideBottom).mas_offset(-20);
    }];
    
    [sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(cancelBtn.mas_right).mas_offset(20);
        make.right.mas_offset(-20);
        make.width.height.centerY.mas_equalTo(cancelBtn);
        
    }];
    
    RAC(sureBtn, enabled) = [RACObserve(actionBtn, selected) distinctUntilChanged];
    
}

- (void)cancelAction:(id)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}

- (void)sureAction:(id)sender{
    
    [USFeedbackTool notifyWarning];
    
    MOAlertBaseView *alert = [[MOAlertBaseView alloc]initWithTitle:@"您确定要注销您的账户吗？" detailTitle:@"购买的历史记录和所有的数据都将会被删除，且无法撤销，确定要注销吗？" contentView:nil leftButtonImageName:nil rightButtonImageName:nil autoDissmiss:YES tapDissmiss:YES];
    @weakify(self)
    alert.didClickIndexBlock = ^(NSInteger index) {
        @strongify(self)
        if (index == 1) {
            [USUser cancelUser];
        }
    };
    alert.titleLabel.textColor = UIColor.us_redColor;
    [alert show];
    
}

 





- (void)readAction:(UIButton *)sender{
    sender.selected = !sender.selected;
    [USFeedbackTool impactLight];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
